package cn.majingjing.core.xml;

import com.thoughtworks.xstream.XStream;

/**
 * @author majinding888@foxmail.com
 * @date 2016-9-23 上午11:18:57
 */
public class XStreamXmlTools {

	public static String toXml(Object obj) {
		XStream xstream = new XStream();
		xstream.autodetectAnnotations(true);
		String xml = xstream.toXML(obj);
		return xml;
	}

	@SuppressWarnings("unchecked")
	public static <T> T fromXML(Class<T> clz, String xml) {
		XStream xstream = new XStream();
		xstream.processAnnotations(clz);
		Object obj = xstream.fromXML(xml);
		return (T) obj;
	}

}
